package com.jarveis.frame.redis.mq;

import org.apache.log4j.Logger;

import redis.clients.jedis.Jedis;

import com.jarveis.frame.redis.RedisManager;

/**
 * @desc 消息生产者
 * @author liuguojun
 * @date 2016-01-14
 */
public class RMQProducer {

	private static final Logger logger = Logger.getLogger(RMQProducer.class);
	private RMQQueue queue;

	/**
	 * 构造方法
	 * 
	 * @param jedis
	 * @param topic
	 * @throws Exception
	 */
	public RMQProducer(final Jedis jedis, final String topic) throws Exception {
		if (jedis == null) {
			logger.info("jedis未成功连接");
			throw new Exception("jedis未成功连接");
		}
		this.queue = new RMQQueue(topic, jedis);
	}

	/**
	 * 构造方法
	 * 
	 * @param topic
	 * @throws Exception
	 */
	public RMQProducer(final String topic) throws Exception {
		Jedis jedis = RedisManager.getConnection();
		if (jedis == null) {
			logger.info("jedis未成功连接");
			throw new Exception("jedis未成功连接");
		}
		this.queue = new RMQQueue(topic, jedis);
	}

	/**
	 * 添加消息
	 * 
	 * @param message
	 */
	public void publish(final String message) {
		queue.publish(message);
	}

	/**
	 * 添加消息
	 * 
	 * @param message
	 * @param istrans
	 * @deprecated
	 */
	public void publish(final String message, boolean istrans) {
		queue.publish(message, istrans);
	}

}